package com.zjp.mg.service;


import com.zjp.mg.dao.AbstractMongoService;
import com.zjp.mg.model.Scheme;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SchemeService extends AbstractMongoService<Scheme> {

    @Override
    public String getCollectionName() {
        return "scheme";
    }

    @Override
    public Class<Scheme> getType() {
        return Scheme.class;
    }

    public Scheme insertByAutoId(Scheme scheme) {
        scheme.setSchemeId(getNextAutoId());
        return insert(scheme);
    }

    public List<Scheme> findByOrderId(Long orderId) {
        Criteria criteria = Criteria.where("orderId").is(orderId);
        return find(Query.query(criteria));
    }
}
